import { createStore, applyMiddleware, combineReducers } from 'redux'
import count from './reducer/count'
import createSage from 'redux-saga'
import rootSage from './sage'

// 1. 创建saga中间件
// 2. 添加到applyMiddleware中
// 3. 执行sageMiddleware下的run函数（目的是为了递归执行里面yeild）
// 4. 使用takeEvery("标识", *函数)开启每个任务
// 5. 使用call发起异步请求
// 6. 通过put来派发任务
const sageMiddleware = createSage()

const reducer = combineReducers({
    count
})

const store = createStore(reducer, applyMiddleware(sageMiddleware))

sageMiddleware.run(rootSage)

export default store